<template>
  <div class="syshome">
    <div class="homeMain">
      <div>
        <div class="numData-cotainer">
          <div class="usersNum">
            用户量:{{ this.usersNum }}
            <div>
              <!-- <el-statistic :value="1 ? 521 : 520" title="今日增长">
                <template slot="suffix">
                  <span class="like">
                    <i class="el-icon-star-on"></i>
                  </span>
                </template>
              </el-statistic> -->
            </div>
          </div>
          <div class="blogsNum">
            博客量:{{ this.blogsNum }}
            <div>
              <!-- <el-statistic :value="1 ? 521 : 520" title="今日增长">
                <template slot="suffix">
                  <span class="like">
                    <i class="el-icon-star-on"></i>
                  </span>
                </template>
              </el-statistic> -->
            </div>
          </div>
          <div class="visitorNum">
            访问量:{{ this.visitorNum }}
            <div>
              <!-- <el-statistic :value="1 ? 521 : 520" title="今日增长">
                <template slot="suffix">
                  <span class="like">
                    <i class="el-icon-star-on"></i>
                  </span>
                </template>
              </el-statistic> -->
            </div>
          </div>
          <div class="todayAdd">站长留言:</div>
        </div>
        <el-row>
          <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
            <div class="usersChartCard">
              <div id="usersChart" :style="{width: '1200px', height: '400px'}"></div>
            </div>
          </el-col>
          <!-- <el-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
            <div class="blogsChartCard">
              <div id="blogsChart" :style="{width: '400px', height: '200px'}"></div>
            </div>
          </el-col>
          <el-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
            <div class="visitorChartCard">
              <div id="visitorChart" :style="{width: '500px', height: '200px'}"></div>
            </div>
          </el-col> -->
        </el-row>
        <el-row>
          <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
            <div class="news">
              <el-card class>
                <div slot="header" class="clearfix">
                  <span>公告</span>
                </div>
                <div>
                  <el-row>
                    <div v-for="(item,index) in notices" :key="index">
                      <el-col class="notices">
                        <div class="noticeProfile">
                          <img :style="{width: '100px', height: '60px'}" :src="item.profile" alt />
                        </div>
                        <el-tag
                          type="success"
                        >{{ item.author }}在{{item.create_time.slice(0,10)}}发布了 :</el-tag>
                        <div class="noticeContent">
                          <span @click="noticesBtn(item)">{{ item.title }}</span>
                        </div>
                      </el-col>
                    </div>
                  </el-row>
                </div>
              </el-card>
            </div>
          </el-col>
          <!-- <el-col :xl="14" :lg="14 " :md="14" :sm="14" :xs="24">
            <div class="notice">
              <el-card class>
                <div slot="header" class="clearfix">
                  <span>工作日历</span>
                </div>
                <div>
                  <Calendar></Calendar>
                </div>
              </el-card>
            </div>
          </el-col> -->
        </el-row>
        <el-row>
          <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
            <el-card class>
              <div slot="header" class="clearfix">
                <span>友情连接</span>
              </div>
              <div>
                <a
                  href="https://blog.csdn.net/LQlove1?spm=1000.2115.3001.5343"
                >博客转载于</a>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getUsersNum,
  getBlogsNum,
  getVisitorNum,
  getNotices,
  getUsersMix
} from "@/api/dataEcgarts";
import Calendar from "@/components/Calendar.vue";
export default {
  name: "sysHome",
  components: {
    Calendar
  },
  data() {
    return {
      usersNum: "",
      blogsNum: "",
      visitorNum: "",
      notices: "",
      userMix: ""
    };
  },
  async mounted() {
    // this.blogsChart();
    // this.visitorChart();
    await this.getDatas();
  },
  computed: {
    userMixOptions() {
      let that = this;
      let option = {
        title: {
          text: "用户占比",
          left: "center"
        },
        tooltip: {
          trigger: "item"
        },
        legend: {
          orient: "vertical",
          left: "left"
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "50%",
            data: [
              { value: that.userMix.rootNum, name: "超管" },
              { value: that.userMix.adminNum, name: "管理员" },
              { value: that.userMix.userNum, name: "用户" },
              { value: that.userMix.demoNum, name: "游客" },
              { value: that.userMix.testNum, name: "测试用户" }
            ],
            //百分比
            label: {
              normal: {
                show: true,
                formatter: "{b}: {c}({d}%)" //自定义显示格式(b:name, c:value, d:百分比)
              }
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              }
            }
          }
        ]
      };
      return option;
    }
  },
  methods: {
    usersChart() {
      // 基于准备好的dom，初始化echarts实例
      let usersChart = this.$echarts.init(
        document.getElementById("usersChart")
      );
      // 绘制图表
      usersChart.setOption(this.userMixOptions);
    },
    // blogsChart() {
    //   // 基于准备好的dom，初始化echarts实例
    //   let blogsChart = this.$echarts.init(
    //     document.getElementById("blogsChart")
    //   );
    //   blogsChart.setOption({
    //     title: {
    //       text: "博客流量",
    //       subtext: "博客数据",
    //       left: "center",
    //       textStyle: 18
    //     },
    //     tooltip: {
    //       trigger: "axis"
    //     },
    //     legend: {
    //       data: ["前端", "后端", "大数据", "全栈", "其他"]
    //     },
    //     grid: {
    //       left: "3%",
    //       right: "4%",
    //       bottom: "3%",
    //       containLabel: true
    //     },
    //     toolbox: {
    //       feature: {
    //         saveAsImage: {}
    //       }
    //     },
    //     xAxis: {
    //       type: "category",
    //       boundaryGap: false,
    //       data: [
    //         "星期一",
    //         "星期二",
    //         "星期三",
    //         "星期四",
    //         "星期五",
    //         "星期六",
    //         "星期天"
    //       ]
    //     },
    //     yAxis: {
    //       type: "value"
    //     },
    //     series: [
    //       {
    //         name: "前端",
    //         type: "line",
    //         stack: "Total",
    //         data: [120, 132, 101, 134, 90, 230, 210]
    //       },
    //       {
    //         name: "后端",
    //         type: "line",
    //         stack: "Total",
    //         data: [220, 182, 191, 234, 290, 330, 310]
    //       },
    //       {
    //         name: "大数据",
    //         type: "line",
    //         stack: "Total",
    //         data: [150, 232, 201, 154, 190, 330, 410]
    //       },
    //       {
    //         name: "全栈",
    //         type: "line",
    //         stack: "Total",
    //         data: [320, 332, 301, 334, 390, 330, 320]
    //       },
    //       {
    //         name: "其他",
    //         type: "line",
    //         stack: "Total",
    //         data: [820, 932, 901, 934, 1290, 1330, 1320]
    //       }
    //     ]
    //   });
    // },
    // visitorChart() {
    //   let visitorChart = this.$echarts.init(
    //     document.getElementById("visitorChart")
    //   );
    //   visitorChart.setOption({
    //     title: {
    //       text: "周访问量",
    //       left: "center"
    //     },
    //     xAxis: {
    //       type: "category",
    //       data: [
    //         "星期一",
    //         "星期二",
    //         "星期三",
    //         "星期四",
    //         "星期五",
    //         "星期六",
    //         "星期天"
    //       ]
    //     },
    //     yAxis: {
    //       type: "value"
    //     },
    //     series: [
    //       {
    //         data: [150, 230, 224, 218, 135, 147, 260],
    //         type: "line"
    //       }
    //     ]
    //   });
    // },
    // 封装一个方法，调用多个接口
    async getDatas() {
      await getUsersNum().then(res => {
        this.usersNum = res.data.usersNum;
      });
      await getBlogsNum().then(res => {
        this.blogsNum = res.data.blogsNum;
      });
      await getVisitorNum().then(res => {
        this.visitorNum = res.data.visitorNum;
      });
      await getNotices().then(res => {
        this.notices = res.data.notices.slice(0, 3);
      });
      await getUsersMix().then(res => {
        this.userMix = res.data.userMix;
        this.usersChart();
      });
    },
    noticesBtn(item) {
      console.log(item);
      this.$alert(item.content, "公告", {
        confirmButtonText: "确定",
        callback: action => {
          this.$message({
            type: "info",
            message: `action: ${action}`
          });
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.syshome {
  height: 83vh;
  .numData-cotainer {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }
  .homeMain {
    height: 83vh;
    overflow: auto;
    background-color: #e9eef3;
  }
  .box-card {
    padding: 0% !important;
    margin: 0%;
    background: #e9eef3;
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    border-radius: 4px;
    border: 1px solid #ebeef5;
  }
  .usersNum,
  .blogsNum,
  .visitorNum,
  .todayAdd {
    text-align: center;
    width: 400px;
    height: 120px;
    line-height: 60px;
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    border-radius: 4px;
    margin-right: 10px;
  }
  .usersNum {
    background-color: #67c23a;
  }
  .blogsNum {
    background-color: #e6a23c;
  }
  .visitorNum {
    background-color: #f56c6c;
  }
  .todayAdd {
    background-color: #909399;
  }
  .usersChartCard {
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    border-radius: 4px;
    border: 1px solid #ebeef5;
    background-color: #fff;
    margin-top: 10px;
  }
  .blogsChartCard,
  .visitorChartCard,
  .news,
  .notice {
    box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    border-radius: 4px;
    border: 1px solid #ebeef5;
    background-color: #fff;
    margin-top: 10px;
  }
  .notices {
    width: 100%;
    height: 80px;
    border-bottom: 1px solid #ebeef5;
    line-height: 80px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    .noticeProfile {
      width: 100px;
      height: 60px;
    }
    .noticeContent {
      width: 300px;
      height: 60px;
      line-height: 60px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow: ellipsis;
      font-size: 18px;
    }
  }
}
</style>